﻿Module modReports

    'note: because this will try to load SQLite.dll compiled with Framework 2.0, I must create an app.config file containing useLegacyV2RuntimeActivationPolicy="true"
    'and make sure that it appears in the bin folder as WRDBReports.exe.config

    Public REGAPP = "WRDBReports"
    Public Project As WRDB.Project.clsProject
    Public ProjectName As String = ""
    Public ReportDir As String = ""

    Public Sub Main()
        ShowReports()
    End Sub

    Public Sub ShowReports()
        Try

            System.Windows.Forms.Application.EnableVisualStyles()

            Dim ProjectName As String = GetSetting(REGAPP, "General", "ProjectName")
            ReportDir = GetSetting(REGAPP, "General", "ReportDir", "")
            Dim ReportName As String = GetSetting(REGAPP, "General", "ReportName", "")

            If Not WRDB.Project.clsConnections.GetProjectList.ContainsKey(ProjectName) Or ReportDir = "" Then
                WarningMsg("This appears to be the first time that you have run WRDB Reports. Please configure the application.")
                With New WRDB.Reports.frmConfigWRDB(ProjectName, ReportDir)
                    If .ShowDialog = DialogResult.OK Then
                        ProjectName = .ProjectName
                        ReportDir = .ReportDir
                        SaveSetting(REGAPP, "General", "ProjectName", ProjectName)
                        SaveSetting(REGAPP, "General", "ReportDir", ReportDir)
                    Else
                        Exit Sub
                    End If
                    .Dispose()
                End With
            End If

            Project = New WRDB.Project.clsProject(ProjectName)
            WRDB.Project.clsProject.TempData = WRDB.Project.clsProject.TempPrefix & "WRDBData"
            With New WRDB.Reports.frmReporting("", "", "", "", ReportDir, 30, ReportName, Project, False, True)
                .ShowDialog()
                ReportName = .cboReports.Text
                If ReportName <> "" Then SaveSetting(REGAPP, "General", "ReportName", ReportName)
            End With


        Catch ex As Exception

            ErrorMsg(, ex)

        End Try

    End Sub

End Module
